package cn.edu.neusoft.food729.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.retroiftdemo_729.R;
import com.squareup.picasso.Picasso;

import java.util.List;

import cn.edu.neusoft.food729.Bean.UserBean;
import cn.edu.neusoft.food729.activity.FoodInfoActivity;
import cn.edu.neusoft.food729.activity.getAllCommentsByUserActivity;
import cn.edu.neusoft.food729.activity.getAllOrdersByUserActivity;
import cn.edu.neusoft.food729.activity.updateUserByIdActivity;
import cn.edu.neusoft.food729.common.Common;
import cn.edu.neusoft.food729.listener.UserListener;
import cn.edu.neusoft.food729.model.UserModel;

public class Fragment5 extends BaseFragment {

    private int page = 1;
    private int lastVisibleItemPosition;
    private ImageButton xinxi;
    private TextView username, tel;
    private Button wddd, wdpl;
    String id, name, pass, tell, adress, comment;

    private UserListener listener = new UserListener() {
        @Override
        public void onResponse(UserBean bean) {
            username.setText("昵称：" + bean.getUsername());
            tel.setText("电话：" + bean.getMobilenum());
            id = String.valueOf(bean.getUser_id());
            name = bean.getUsername();
            tell = bean.getMobilenum();
            pass = bean.getUserpass();
            adress = bean.getAddress();
            comment = bean.getComment();
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(context, "失败" + msg, Toast.LENGTH_SHORT).show();
        }
    };

    public Fragment5() {
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//        return super.onCreateView(inflater, container, savedInstanceState);
        return inflater.inflate(R.layout.fragment5,container,false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        System.out.println("--f1--" + getSessionId());//父类

        UserModel userModel = new UserModel();
        userModel.getResultList(Integer.valueOf(getSessionId()), listener);
        xinxi = view.findViewById(R.id.imageButton4);
        username = view.findViewById(R.id.textView10);
        tel = view.findViewById(R.id.textView4);
        wddd = view.findViewById(R.id.wddd);
        wdpl = view.findViewById(R.id.wdpl);

        xinxi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), updateUserByIdActivity.class);
                intent.putExtra("id", id);
                intent.putExtra("username", name);
                intent.putExtra("userpass", pass);
                intent.putExtra("tel", tell);
                intent.putExtra("adress", adress);
                intent.putExtra("comment", comment);
                startActivity(intent);
            }
        });

        wddd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), getAllOrdersByUserActivity.class);
                startActivity(intent);
            }
        });

        wdpl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), getAllCommentsByUserActivity.class);
                startActivity(intent);
            }
        });


    }


}
